﻿//-----------------------------------------------------------------------
// <copyright file="PrintSOEPropertyPage.cs" company="WorldView Solutions Inc">
//     Copyright (c) WorldView Solutions Inc. This source is subject to the Microsoft Public License (Ms-PL). All other rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace WorldViewSolutions.ArcGISServer.ArcCatalog
{
    [System.Runtime.InteropServices.Guid("EB2883EC-3E95-4e29-B69E-C1926D29D88E")]
	public class PrintSOEPropertyPage : BaseSOEPropertyPage
	{
		#region Member Variables

		private ESRI.ArcGIS.esriSystem.IPropertySet _extensionProperties;
		private ESRI.ArcGIS.esriSystem.IPropertySet _serverObjectProperties;
		private string _extensionType;
		private string _serverObjectType;
        private PrintSOEPropertyForm _propertyPage;

		#endregion		

		public PrintSOEPropertyPage()
		{
            _propertyPage = new PrintSOEPropertyForm();

			_serverObjectType = "MapServer";

			// Must be the same name used when registering the SOE.
			_extensionType = "PrintSOE";
		}

        ~PrintSOEPropertyPage()
		{
			_propertyPage.Dispose();
			_propertyPage = null;
		}

		#region SOEPropertyPage Members

		#region Inherited from IComPropertyPage - Activate, Show, Hide, PageSite

		/// <summary>
		/// PageSite permits accessed to the PageChanged method, which, when fired, enables the Apply button on the property page
		/// </summary>
		public override ESRI.ArcGIS.Framework.IComPropertyPageSite PageSite
		{
			set { _propertyPage.PageSite = value; }
		}

		/// <summary>
		/// Displays the form defining the property page's UI
		/// </summary>
		public override void Show()
		{
			_propertyPage.Show();
		}



		/// <summary>
		/// Hides the form containing the property page's UI
		/// </summary>
		public override void Hide()
		{
			_propertyPage.Hide();
		}

		/// <summary>
		/// Fired when the property page is activated
		/// </summary>
		/// <returns>the handle of the form containing the property page's UI</returns>
		public override int Activate()
		{
			return _propertyPage.getHWnd();
		}

		#endregion

		#region Inherited from IAGSSOEParameterPage - ServerObjectProperties, ExtensionProperties, ServerObjectExtensionType, ServerObjectType

		/// <summary>
		/// Properties of the server object on which the extension is configured.
		/// </summary>
		public override ESRI.ArcGIS.esriSystem.IPropertySet ServerObjectProperties
		{
            get
            {
                return _serverObjectProperties;
            }
			set
			{
				_serverObjectProperties = value;
			}
		}

		/// <summary>
		/// Properties of the extension for the current server object.
		/// </summary>
		public override ESRI.ArcGIS.esriSystem.IPropertySet ExtensionProperties
		{
			get
			{
				// Checking the SOE in ArcCatalog adds the following properties into the 
				// map server cfg file -or- existing properties are updated							
                _extensionProperties.SetProperty("TemplateDirectory", _propertyPage.TemplateDirectory);
				return _extensionProperties;
			}
			set
			{
				// Pass the extension properties to the property form
				_extensionProperties = value;
                _propertyPage.TemplateDirectory = _extensionProperties.GetProperty("TemplateDirectory").ToString();

			}
		}

		/// <summary>
		/// The type of the SOE.  This must match the name of the SOE as defined when it is 
		/// registered with the SOM.
		/// </summary>
		public override string ServerObjectExtensionType { get { return _extensionType; } }

		/// <summary>
		/// The type of server object that the SOE extends.  This SOE extends MapServer server objects.
		/// </summary>
		public override string ServerObjectType { get { return _serverObjectType; } }

		#endregion

		#endregion
	}
}
